var express = require('express');
var router = express.Router();
const { get, add, change,deleteID,getOne,getComm } = require("../api/secondKill")

//获取全部数据请求
router.get('/', async function (req, res, next) {
    let { curPage, eachPage } = req.query;
    let data = await get({ curPage, eachPage });
    res.send(data);
});

//getone请求
router.get('/getOne', async function (req, res, next) {
    const{_id} =req.query;
    console.log(_id);
    const data = await getOne({ _id});
    res.send(data);
});

//新增秒杀请求
router.post('/addSk', async function (req, res, next) {
    let { Sale, Time, CommId, count} = req.body;
    console.log( Sale, Time, CommId, count);
    let data = await add({ Sale, Time, CommId, count });
    res.send(data);
});

// 更新秒杀状态
router.put('/changeSk', async function (req, res, next) {
    const {Sale, Time, count, isAttend,_id,CommId} = req.body;
    console.log({Sale, Time, count, isAttend,_id});
    const data = await change({Sale, Time, count, isAttend,_id,CommId});
    res.send(data);
});

//删除秒杀商品
router.delete('/deleteSk', async function (req, res, next) {
    const{_id} =req.query;
    console.log(_id);
    const data = await deleteID({ _id});
    res.send(data);
});
// 获取单个秒杀
router.get('/getComm', async function (req, res, next) {
    const{_id} =req.query;
    console.log(_id);
    const data = await getComm({ _id});
    res.send(data);
});

module.exports = router;